<template>
  <div class="login_conteainer">
    <div class="login_body">
      <!-- 表单头像 -->
      <div class="login_logo">
        <img src="../assets/logo.png" alt="">
      </div>
      <!-- 表单填写内容区 -->
      <el-form ref="loginFormRef" :model="loginForm" :rules="loginFormRules" abel-width="0px" class="login_form">
        <!-- 账号 -->
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid" placeholder="请输入账号"></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input v-model="loginForm.password" prefix-icon="el-icon-lock" placeholder="请输入密码" show-password></el-input>
        </el-form-item>
        <!-- 按钮区域 -->
          <el-form-item class="login_Btn">
            <el-button type="primary" @click="loginBtn">登录</el-button>
            <el-button type="info" @click="loginReset">重置</el-button>
          </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      loginFormRules: {
        username: [
          { required: true, message: '请输入登录名称', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 点击重置 重置表单校验
    loginReset() {
      this.$refs.loginFormRef.resetFields()
    },
    // 登录验证
    loginBtn() {
      this.$refs.loginFormRef.validate(async valid => {
        if (!valid) return
        // const data = await this.$http.post('login', this.loginForm)
        // if (data.code !== 1) return this.$message.error('登录失败!')
        // this.$message.success('登录成功')
        // window.sessionStorage.setItem('token', data.data.token)
        // this.$router.push('/Home')
        if (this.loginForm.username !== 'admin') return this.$message.error('账号错误')
        if (this.loginForm.password !== '123456') return this.$message.error('密码错误')
        window.sessionStorage.setItem('token', 'zidingyishuadksadjlasdj')
        this.$router.push('/Home')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login_conteainer {
  background: #2b4b6b;
  height:100%
}

.login_body{
  width: 450px;
  height: 300px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}

.login_logo{
  width: 130px;
  height: 130px;
  border-radius: 50%;
  border: 1px solid #eee;
  padding: 10px;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  position: absolute;
  left: 50%;
  transform: translate(-50%,-50%);
  background: #fff;
  img{
    width: 100%;
    height: 100%;
    background: #eee;
    border-radius: 50%;
  }
}

.login_form{
  width: 100%;
  position: absolute;
  bottom: 0;
  padding: 0 20px;
  box-sizing: border-box;
  .login_Btn{
   display: flex;
   justify-content: flex-end;
  }
}
</style>
